package main

import (
	"GoServer/entrance"
	"GoServer/utils/config"
	"GoServer/utils/debug"
	"GoServer/utils/service"
	"flag"
	"fmt"
	"os"
	"strings"
)

// 启动方法
// 启动示例
// start service.exe -module=game_xp -port=8080
var (
	programName = flag.String("module", "", "The name of the test to run")
)

func main() {
	config.InitConfigs()                                                /// 初始化配置信息
	debug.InitLogConfig(config.GetConfig("app").GetInt("servers.mode")) // 初始化日志系统

	flag.Parse()

	if *programName == "" {
		fmt.Println("Unknown module:", *programName)
		os.Exit(1)
		return
	}

	fmt.Println("Full module name:", *programName)

	// 提取下划线后的部分
	parts := strings.SplitN(*programName, "_", 2)
	if len(parts) == 2 {
		fmt.Println("Suffix after underscore:", parts[1])
		if parts[0] == "game" {
			port := config.GetConfig("app").GetString(parts[1] + ".port")
			entrance.Main(parts[1], ":"+port)
			service.BeginService(parts[1], ":"+port)
		} else {
			fmt.Println("Unknown module:", *programName)
			os.Exit(1)
		}
	} else {
		fmt.Println("No underscore found in module name.")
		os.Exit(1)
	}
}
